//
//  DEWGroupChatTableCell.m
//  OtherDemo
//
//  Created by lianjie on 2018/7/30.
//  Copyright © 2018年 lianjie. All rights reserved.
//

#import "DEWGroupChatTableCell.h"

@implementation DEWGroupChatTableCell



-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
    }
    return self;
}

-(void)createGroupCellWithInfo:(NSMutableDictionary *)chatInfo andStyle:(DEWGroupCellStyle)style
{
    ///头像
    NSMutableArray *phones = [NSMutableArray array];
    
    NSArray *arr = chatInfo[@"groupAvatarUri"];
    
    for (int i = 0; i<arr.count; i++) {
        
        NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",SERVER_URLIMAGE,arr[i]]]];
        UIImage *image = [UIImage imageWithData:data];
        [phones addObject:image];
        
    }
    
    
    UIView *headerView = [JJHeaders createHeaderView:45 images:phones];
    headerView.x = Margin_15;
    headerView.y = Margin_15;
    [self.contentView addSubview:headerView];
    
    ///name
    UILabel *nameLab = [[UILabel alloc]init];
    nameLab.frame = CGRectMake(headerView.right+Margin_15, Margin_15, Device_Width-90-headerView.right-Margin_15, 45.0f);
    nameLab.font = [UIFont systemFontOfSize:16];
    nameLab.textColor = Color_33;
    [self.contentView addSubview:nameLab];
    
    nameLab.text = [NSString FMAT:chatInfo[@"groupName"]];
    
    if (style == DEWGroupCellStyleEdit) {///具有编辑状态
        ///
        NSString *type = [NSString FMAT:chatInfo[@"applyType"]];
        
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(Device_Width-90, 25, 75, 25);
        [self.contentView addSubview:btn];
        [btn addTarget:self action:@selector(groupListCellAction) forControlEvents:UIControlEventTouchUpInside];
        btn.titleLabel.font = [UIFont systemFontOfSize:13];
        [btn setTitleColor:UIColorFromRGB(0xFF8900) forState:UIControlStateNormal];
        NSString *title = @"";
        if ([type isEqualToString:@"0"]) {///未申请
            title = @"申请加入";
            
            btn.layer.cornerRadius = 4.0;
            btn.layer.borderColor = UIColorFromRGB(0xFF8900).CGColor;
            btn.layer.borderWidth = 1.0f;
            btn.layer.masksToBounds = YES;
            
            
        }else if ([type isEqualToString:@"1"]){///申请中
            title = @"申请中...";
            btn.userInteractionEnabled = NO;
            
        }else{///已申请
            title = @"已加入";
            [btn setTitleColor:Color_99 forState:UIControlStateNormal];
            btn.userInteractionEnabled = NO;
        }
        [btn setTitle:title forState:UIControlStateNormal];
    }
}

-(void)setChatInfo:(NSMutableDictionary *)chatInfo
{
    _chatInfo = chatInfo;
}

///申请加入
- (void)groupListCellAction
{
    if (_joinDelegate && [_joinDelegate respondsToSelector:@selector(didGroupCellItemBackInfo:)]) {
        [_joinDelegate didGroupCellItemBackInfo:self.chatInfo];
    }
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
